package com.clwl.supervise.superviseapp.entity.result;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

/**
 * 返回信息
 */
public class ResultEntity<T> {


    private Integer code;

    private String message;
    @JsonSerialize(include =JsonSerialize.Inclusion.NON_NULL )
    private T data;

    public static<T>   ResultEntity<T> success(String message){
        ResultEntity<T> resultEntity = new ResultEntity<T>(ResultCode.SUCCESS);
        resultEntity.setMessage(message);
        try {
            resultEntity.setData((T)message);
        } catch (Exception e) {

        }
        return resultEntity;
    }
    public static<T>   ResultEntity<T> success(T data){
        ResultEntity<T> resultEntity = new ResultEntity<T>(ResultCode.SUCCESS,data);
        return resultEntity;
    }

    public static<T>   ResultEntity<T> success(T data,String timestamp){
        ResultEntity<T> resultEntity = new ResultEntity<T>(ResultCode.SUCCESS,data,timestamp);
        return resultEntity;
    }

    public static<T> ResultEntity<T> success(){
        ResultEntity<T> resultEntity = new ResultEntity<T>(ResultCode.SUCCESS);
        return resultEntity;
    }

    public static<T> ResultEntity<T> error(ResultCode code){
        ResultEntity<T> resultEntity = new ResultEntity<T>(code);
        return resultEntity;
    }

    public static<T> ResultEntity<T> error(String message){
        ResultEntity<T> resultEntity = new ResultEntity<T>(ResultCode.ERROR);
        resultEntity.setMessage(message);
        return resultEntity;
    }




    ResultEntity (ResultCode code){
        this.code = code.code();
        this.message =  code.message();
    }
    public  ResultEntity (ResultCode code ,T data){
        this.code = code.code();
        this.message = code.message();
        this.data = data;
    }

    public  ResultEntity (ResultCode code ,T data,String timestamp){
        this.code = code.code();
        this.message = code.message();
        this.data = data;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
